package com.xuhnagchen.automation.controller;


import com.google.gson.Gson;
import com.xuhnagchen.automation.entity.UserBean;
import com.xuhnagchen.automation.service.UserService;
import com.xuhnagchen.automation.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    @Autowired
    UserService service;

    private String[] names = new String[]{"一夜奈良山", "嘴角的樱桃汁", "牛奶煮萝莉", "桃花下浅酌", "闺怨无梦", "醉酒鞭名马", "软糯酥胸", "黑魅惑", "侵她城做她王"};

    //获取IP地址
    @RequestMapping(value = "/loginUser",  produces = {"application/json;charset=UTF-8"})
    public String loginUser(@RequestParam(name = "userName") String userName, @RequestParam(name = "password") String password, HttpServletRequest request) {
        log.debug("userName:" + userName + ",password:" + password);
        result = service.getUserInfo(userName, password, result);
        if (result.getCode() ==1){
            request.setAttribute("userID","1");
            return "sendEmail.html";
        }
        return ResultUtil.getReturn(result);

    }

    @RequestMapping("/findAll")
    public List<UserBean> findAll(){
        return service.findAll();
    }
    @RequestMapping("/findUser")
    public UserBean findUserById(@RequestParam(name = "id") long id){
        return service.findUserById(id);
    }
}
